#include "mainwindow.h"
#include <QApplication>
#include <QTextCodec>
#include <QFontDatabase>
#include <pthread.h>
#include <unistd.h>
#include <iostream>

extern "C" {
    int cdj_run();
    int qt_func(char *str);
}

#if 0 // no use
class MySignal : public QObject
{
    Q_OBJECT
public:
    int signal(const char *arg)
    {
        emit send_signal(arg);
    }

signals:
    int send_signal(const char *arg);

};
#endif

void* cdj_thread(void *argv)
{
    cdj_run();
    return NULL;
}

int cdj_start()
{
    pthread_t id;
    pthread_create(&id, NULL, cdj_thread, NULL);
    return 0;
}

MainWindow *g_pMainWindow = NULL;
int qt_func(char *str)
{
    if (!g_pMainWindow)
        return -1;
    g_pMainWindow->signal(str);

    return 0;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
    QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf-8"));

    QFontDatabase::addApplicationFont("wqy-microhei.ttc");
    QFont font;
    font.setPixelSize(20);
    font.setFamily("WenQuanYi Micro Hei");
    font.setBold(false);
    a.setFont(font);
#endif

    MainWindow w;
    w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    w.show();

    g_pMainWindow = &w;
    w.init_signal();
    // 启动车道机
    cdj_start();

    return a.exec();
}
